var glob = require('glob');
var path = require('path');
var JavaScriptObfuscator = require('webpack-obfuscator');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack')
//entries函数
var entries = function () {
    var jsDir = path.resolve(__dirname, 'src')
    var entryFiles = glob.sync(jsDir + '/*.{js,jsx}')
    var map = {};
    for (var i = 0; i < entryFiles.length; i++) {
        var filePath = entryFiles[i];
        var filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'));
        map[filename] = filePath;
    }
    console.log(map);
    return map;
}
module.exports = {
    entry: entries(),
    output: {
        path: path.resolve(__dirname) + '/../static/js',
        filename: '[name].js'
        /*
            (chunkData) => {
            // var arr=chunkData.chunk.name.split('_');
            return chunkData.chunk.name+'.js';
        }
        */
    },
    externals: {
        'Alpine':'window.Alpine',
    },
    module: {
        rules: [{
            test: /\.css$/,
            use: ['style', 'css']
        },{
            test: /\.js$/,
            use: ['babel-loader']
        },
            {
                test: /\.html$/,
                loader: 'raw-loader'
            }
        ]
    },
    plugins: [


        /*
        new CopyWebpackPlugin({patterns:[
            {
               from:'./public',//想要复制的文件夹
               to: path.resolve(__dirname,'../../../')+'/public' //复制在哪个文件夹
            }
        ]})
        */


        // new JavaScriptObfuscator({
        //     rotateStringArray: true,
        //     reservedStrings: ['\s*'],
        //     disableConsoleOutput: true
        // })
    ],
    optimization: {
        // minimize: true,
        // splitChunks: {
        //     cacheGroups: {
        //         commoms: {
        //             name: 'chunks_qe',
        //             chunks: 'initial',
        //             minChunks: 2
        //         }
        //     }
        // }
    }
};
